package com.yangsen.register;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.yangsen.login.LoginService;

public class RegisterController extends Controller {

    private static final RegisterService srv = RegisterService.me;

    public void index() {
        render("index.html");
    }

    @Before(RegisterValidator.class)
    public void register(String username, String pwd, String nickname) {
        Ret ret = srv.register(username, pwd, nickname);
        if (ret.getBoolean("status")) {
            setCookie(LoginService.USER, ret.getStr("token"), 60 * 60);
        }
        renderJson(ret);
    }
}
